<template>
  <div class="app">
    <van-nav-bar
      title="动态详情"
      left-text=""
      left-arrow
      @click="backlink()"
    ></van-nav-bar>
    <div class="container">
      <div class="avatar-box">
        <div class="avatar-part">
          <img v-lazy="trendinfo.avatarurl" />
        </div>
        <div class="info-part" @click="gotolinkwithdata">
          <div class="avatarname">{{ trendinfo.nickname }}</div>
          <div class="info-button">
            <div class="avatardate">{{ trendinfo.time }}</div>
            <div class="location">
              <icon-svg
                icon-class="position"
                icon-color="#304056"
                class="dingwei-icon"
              ></icon-svg>
              北京市
            </div>
          </div>
        </div>
        <div class="follow-part">
          <van-button class="follow-btn" type="primary">关注</van-button>
        </div>
      </div>
      <div class="content">
        {{ trendinfo.content }}
      </div>
      <div v-if="trendinfo.images.length > 0" class="trendimg">
        <img
          v-for="(i, index1) in trendinfo.images"
          :key="index1"
          v-lazy="i"
          alt=""
          @click="showpic(index1)"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { showImagePreview } from "vant";
export default {
  data() {
    return {
      trendinfo: {},
    };
  },
  methods: {
    backlink() {
      this.$router.back();
    },
    showpic(index) {
      showImagePreview({
        images: this.trendinfo.images,
        startPosition: index,
      });
    },
    gotolinkwithdata() {
      this.$router.push({
        name: "UserPage",
        params: {
          userinfo: JSON.stringify(this.trendinfo),
        },
      });
    },
  },
  created() {
    this.trendinfo = JSON.parse(this.$route.params.trendinfo);
  },
};
</script>

<style scoped>
.app {
  margin: 0;
  padding: 0;
  background-color: #f2f3f5;
  min-height: 100vh;
}
.container {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  margin-top: 10px;
  background-color: white;
}
.avatar-box {
  display: flex;
  width: 95%;
  margin: 0 auto;
  height: 1.5rem;
}
.avatar-part {
  width: 60px;
  height: 60px;
  overflow: hidden;
  border-radius: 50%;
}
.avatar-part img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.info-part {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 16px;
  margin-left: 5px;
}
.avatarname {
  font-size: 20px;
  font-weight: 550;
}

.info-button {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  color: #969799;
  margin-bottom: 5px;
}
.dingwei-icon {
  width: 18px;
  height: 18px;
  margin-right: -5px;
}

.location {
  margin-left: 10px;
}

.follow-part {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-left: auto;
}
.follow-btn {
  width: 50px;
  height: 25px;
  font-size: 14px;
  border-radius: 5px;
  padding: 0 !important;
}
.content {
  width: 95%;
  margin: 0 auto;
  margin-top: 5px;
  margin-bottom: 5px;
  font-size: 16px;
}
.trendimg {
  width: 95%;
  margin: 10px auto 10px auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 5px;
}

.trendimg img {
  width: 100%;
  border-radius: 10px;
  height: auto; /* 将高度设置为自动以确保宽高比不变 */
  aspect-ratio: 1 / 1; /* 设置宽高比为1:1，即正方形 */
  object-fit: cover;
}
</style>